import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import 'dayjs/locale/zh-cn';
import ElementUI from 'element-plus';
import 'element-plus/dist/index.css';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import { createApp, reactive } from 'vue';
import VXETable from 'vxe-table';
import 'xe-utils';
import 'vxe-table/lib/style.css';
import App from './App.vue';
import EventBus from './event-bus/EventBus.ts';
import router from './router';
import store from './store';


// 如果需要使用sweetui开发，请在package.json中引入下面两个依赖，方便本地开发，而在环境上会使用xvue提供的sweetui，在vite打包配置中会剔除掉sweetui
// "@hw-seq/sweet-ui-base": "5.3.17",
// "@hw-seq/sweet-ui-icons": "5.3.0",
// import sweetBase from '@hw-seq/sweet-ui-base';
// import '@hw-seq/sweet-ui-base/theme-chalk/sweet/index.css'; // 按需引入sweetui中以sweet开头的类名样式
// import sweetUIIcon from '@hw-seq/sweet-ui-icons';

(async() => {
  const app = createApp(App);
  window.xVueWeb = {};
  window.xVueWeb.app = app;
  if (!window.xVueWeb.app.config) {
    window.xVueWeb.app.config = {};
  }
  window._adoPremise = { // 打包页面资产包时，避免报错（不知道为什么不生效了）
    uc: {
      theme: 'light', // light | dark
      languages: {},
    },
  };
  const data = [{
    s: '吉利莲',
    count: 300,
    isFlag0: 0,
    isFlag1: 1,
    str: 'hello',
    longStr: 'hello world, who are you, 你好吗',
    int: 100,
    float: 90.15415,
    num1: 300,
    num2: 400,
    data: '2023-09-27',
    data1: '2023-10-27',
    max: 50,
    min: 10,
    average: 30,
    start: 20,
    end: 45,
  }, {
    s: '巧克力',
    count: 300,
    isFlag0: 0,
    isFlag1: 1,
    str: 'hello',
    longStr: 'hello world, who are you, 你好吗',
    int: 100,
    float: 90.15415,
    num1: 300,
    num2: 400,
    data: '2023-09-28',
    data1: '2023-11-28',
    max: 80,
    min: 40,
    average: 60,
    start: 50,
    end: 75,
  }];
  app.config.globalProperties.xvGlobalRfs = {

    // 样例数据
    api1: reactive({
      data: data,
      run() {
        window.showLog('api1.run success');
      },
    }),
  };
  app.config.globalProperties.$xvueDataStructs = [];
  app.config.globalProperties.$eventHub = app.config.globalProperties.$eventHub || new EventBus();
  app.config.globalProperties.$adoPremiseEvtBus = new EventBus();
  app.config.globalProperties.pageId = 'local_pageid';
  app.config.globalProperties.dacTransDataFormat = true;

  
  if (process.env.NODE_ENV === 'development') {
    await import('./common/window-vars.js');
    await import('./utils/interception-new.js');
    await import('./logic/lang.js');
    await import('./logic/components');
    await import('./plugins');
    await import('./common/index_logic_design.js');
  }

  app.use(ElementUI, { locale: zhCn });
  app.use(VXETable);
  app.use(router);
  app.use(store);
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
  }

  // sweetBase.i18n('zh_CN', app);
  // sweetBase.i18n('en_US', app);
  // sweetBase.setTheme('light');
  // app.use(sweetBase);
  // app.use(sweetUIIcon);

  // 保证环境信息先生成再执行
  const init = () => {
    app.mount('#app');
  };
  init();
})();
